package Chapter5;

public class Example04 {
	public static void main(String[] args) {
		new TicketWindow().start();
		new TicketWindow().start();
		new TicketWindow().start();
		new TicketWindow().start();
	}

}

class TicketWindow extends Thread{
	private int tickets=100;
	public void run() {
		while(true) {
			if (tickets>0) {
				Thread th=Thread.currentThread();
				String th_name=th.getName();
				System.out.println(th_name+"正在大厅发售第 "+tickets--+"张票");
						
			}
		}
	}
}//每个窗口都卖了100张票说明线程没有共享资源。例5就改进了这个方法